import random
from chart.die import Die
from plotly.graph_objs import Bar,Layout
from plotly import offline

# 创建一个D6和D10
die_1 = Die()
die_2 = Die(10)

# 掷几次骰子并将结果存储在一个列表中
results = []
for roll_num in range(50_000):
    result = die_1.roll()+die_2.roll()
    results.append(result)

# 分析结果
frequencies = []
max_result = die_1.num_sides+die_2.num_sides
for value in range(2,max_result+1):
    frequency = results.count(value)
    frequencies.append(frequency)

# 对结果进行可视化
x_values = list(range(2,max_result+1))
data = [Bar(x=x_values,y=frequencies)]  # Bar()类用于绘制条形图的数据集

x_axis_config = {'title':'结果','dtick':1} #dtick指定了x轴间的刻度距离
y_axis_config = {'title':'结果的频率'}
my_layout = Layout(title='掷一个D6和一个D10 50_000次的结果',xaxis=x_axis_config,yaxis=y_axis_config)
report = random.randint(2,11)
offline.plot({'data':data,'layout':my_layout},filename='D%s.html'%report)

